<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test IFrame</title>
<script type="text/javascript">
//<![CDATA[
var stored_selection = null;
var is_focus = false;

function write(str)
{
	var m = document.getElementById('msg');
	var node;

	node = document.createElement('div');
	node.innerHTML = str;
	m.appendChild(node);
}
function get_iframe()
{
	var f = document.getElementById('if');
	return f;
}
function restore_select()
{
	write('restore_select');
	if(stored_selection) {
		stored_selection.select();
	}
	stored_selection = null;
}
function save_select()
{
	write('save_select');
	var f = document.getElementById('if');
	var fwin = f.contentWindow;

	stored_selection = fwin.document.selection.createRange();
}
function turnon_design()
{
	var f = document.getElementById('if');
	var fwin = f.contentWindow;

	fwin.document.designMode = 'on';
	fwin.document.onselectionchange = function() {
		if(is_focus) save_select();
	}
	f.onfocus = function() {
		restore_select();
		is_focus = true;
		write('onfocus');
		save_select();
	}
	f.onblur = function() {
		is_focus = false;
		write('onblur');
	}
}
//]]>
</script>
</head>
<body>
<iframe id="if" src="blank.html" width="700" height="300">
</iframe>
<button onclick="javascript:save_select();">Save</button>
<button onclick="javascript:restore_select();">Restore</button>
<script type="text/javascript">
//<![CDATA[
setTimeout(turnon_design,500);
//]]>
</script>
<div id="msg">
</div>
</body>
</html>
